﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mogre;

namespace ProjetSMA.View.Mogre
{
    public class Die3D
    {
        private SceneManager m_scmgr;
        private string m_name = "_def";
        private Root m_root;


        private List<string> m_list_node_name = new List<string>();
        private float m_cpt = 0;
        private Random m_rd = new Random();
        private SceneNode m_node;
        private ParticleSystem m_system;

        private System.Timers.Timer m_timer;


        public Die3D(Root par_root, SceneManager par_sc, string par_name, Vector3 par_parent)
        {
            m_scmgr = par_sc;
            m_name = par_name + m_rd.Next(-9992, 9992) +"_die";
            m_root = par_root;

            m_node = m_scmgr.RootSceneNode.CreateChildSceneNode(m_name);
            m_node.Position = par_parent + new Vector3(0, 10, 0);

        }

        public bool Live_Frame(FrameEvent evt)
        {

            m_cpt += 0.03f;
            if (m_cpt > 1)
                Destroy();

            return true;
        }

        public void Initialisation()
        {
            m_system = m_scmgr.CreateParticleSystem(m_name, "Fire/FireworksBis");
            m_node.AttachObject(m_system);
            m_root.FrameStarted += new FrameListener.FrameStartedHandler(Live_Frame);
        }

        public void Run()
        {
            m_root.FrameStarted += new FrameListener.FrameStartedHandler(Live_Frame);
            m_system.Emitting = true;
            m_cpt = 0;
        }


        public void Destroy()
        {
            m_root.FrameStarted -= new FrameListener.FrameStartedHandler(Live_Frame);
            m_system.Emitting = false;
        }


    }
}
